<template>
  <view class="">
    <template v-if="showScanSuc">
		<view class="page">
			<view class="scan_sta">
			  <view class="icon_biao">
			    <u-icon name="checkmark"color="#fff" size="50"></u-icon>
			  </view>
			  <view class="suctxt">
			    公寓入住人员
			  </view>
			
			</view>
			<view class="xb-info">
			  <view>
			    <text>入住姓名</text>
			    <text>{{info.name}}</text>
			  </view>
			  <view>
			    <text>联系电话</text>
			    <text>{{info.phone}}</text>
			  </view>
			  <view>
			    <text>身份证号</text>
			    <text>{{info.identityCard}}</text>
			  </view>
			  <view>
			    <text>性别</text>
			    <text>{{info.sex}}</text>
			  </view>
			  <view>
			    <text>企业名称</text>
			    <text>{{info.enterpriseName}}</text>
			  </view>
			  <view>
			    <text>所属园区</text>
			    <text>{{info.parkNum}}</text>
			  </view>
			  <view>
			    <text>公寓门牌号</text>
			    <text>{{info.roomNum}}</text>
			  </view>
			</view>
			
			<view class="xb-info">
				<view>
					<text>当前时间</text>
					<text>{{nowDate}}</text>
				</view>
			</view>
		</view>
     
    </template>
    <template v-if="showScanFal">
      <view class="fal_box">
        <view class="icon_biao" style="background: #F74D39">
          <u-icon name="error"color="#fff" size="50"></u-icon>
        </view>
        <view class="suctxt"  style="color: #F74D39">
          禁止进入
        </view>
        <view style="margin-top: 10rpx;font-size: 28rpx;color: #999999;">
          不属于园区公寓人员
        </view>
      </view>
    </template>
  </view>
</template>

<script>
import { data } from 'uview-ui/libs/mixin/mixin';
export default {
  data() {
    return {
      userAc: null,
      reqForm: {
        phone: '',
        parkNum: 'A'
      },
      info:null,
      showScanSuc:false,
      showScanFal:false,
	  nowDate:''
    };
  },
  onLoad(opts) {
	   this.getNowTime()
    if (opts.q) {
      let url = decodeURIComponent(opts.q);
      this.reqForm.parkNum = getQueryString(url, 'parkNum')
      function getQueryString(url, name) {
        var reg = new RegExp('(^|&|/?)' + name + '=([^&|/?]*)(&|/?|$)', 'i');
        var r = url.substr(1).match(reg);
        if (r != null) {
          return r[2];
        }
        return null;
      }
    }
    let isLogin = uni.getStorageSync("isLogin")
    if (isLogin) {
      this.userAc = uni.getStorageSync("userAc")
      let loginType = this.userAc.loginType
      if (loginType == "account") {
        this.reqForm.phone = this.userAc.userInfo.phonenumber
      } else {
        this.reqForm.phone = this.userAc.phone
      }
      this.scanCode()
    } else {
      this.navTo("/pages/login2/login2")
    }


  },
  methods: {
	  getNowTime(){
		  setInterval(()=>{
			  let nowt=new Date()
			  this.nowDate=nowt.toLocaleString()
		  },1000)
	  },
    scanCode() {
      uni.scanCode({
        success: (res) => {
          console.log("条码类型：" + res.scanType);
          console.log("条码内容：" + res.result);
          function getQueryVariable(variable){
            let query = res.result;
            let vars = query.split("&");
            for (let i=0;i<vars.length;i++) {
              let pair = vars[i].split("=");
              if(pair[0] == variable){return pair[1];}
            }
            return(false);
          }

          this.reqForm.parkNum=  getQueryVariable("parkNum")
          console.log("this.reqForm.parkNum",this.reqForm.parkNum)
          this.apis.lifeApi.lifeApartmentPerson(this.reqForm).then(res=>{
            if (res.rows.length<1){
              this.showScanFal=true
            }else {
              this.showScanSuc=true
              this.info=res.rows[0]
            }
          })
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.page {
  padding-bottom: 112 rpx;
}
.scan_sta{
  background: #FFFFFF;
  border-radius: 12rpx;
  opacity: 1;
  width: 100%;
  padding-top: 60rpx;
  padding-bottom: 42rpx;
  margin-bottom: 20rpx;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;

}

.icon_biao{
  margin-bottom: 30rpx;
  width: 104rpx;
  height:104rpx;
  border-radius: 50%;
  background: #44D94B;
  display: flex;
  align-items: center;
  justify-content: center;
}
.suctxt{
  font-size: 46rpx;
  font-weight: 500;
  color: #44D94B;
}
.fal_box{
  width: 100%;
  height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background: #fff;
}
</style>
